import { defineStore } from 'pinia'
import { reqLogin } from '@/api/login'
import { useUserStore } from './userStores'
import { ElMessage } from 'element-plus'
import router from '@/router'

// const userStore = useUserStore()

export const useLoginStore = defineStore('loginStore', () => {
  const nameAndPasswordLogin = async (data: any) => {
    const result = await reqLogin(data)
    if (result.code === 200) {
      localStorage.setItem('accessToken', result.data.accessToken)
      localStorage.setItem('refreshToken', result.data.refreshToken)
      return Promise.resolve(result)
    } else {
      return Promise.reject(result)
    }
  }

  return { nameAndPasswordLogin }
})
